// #include <algorithm>

// class Solution
// {
// public:
//     int removeDuplicates(vector<int> &nums)
//     {
//         auto last = unique(nums.begin(), nums.end());
//         return last - nums.begin();
//     }
// };

class Solution
{
public:
    int removeDuplicates(vector<int> &nums)
    {
        int removed = 0;
        int i = 0;
        int length = nums.size();
        while (i + removed < length - 1)
        {
            if (nums[i] == nums[i + removed + 1])
            {
                ++removed;
            }
            else
            {
                ++i;
                nums[i] = nums[i + removed];
                
            }
        }
        return length - removed;
    }
};